package com.lalilu.lmedia.database

import androidx.room.AutoMigration
import androidx.room.Database
import androidx.room.DeleteTable
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import androidx.room.migration.AutoMigrationSpec
import com.lalilu.lmedia.entity.LHistory
import com.lalilu.lmedia.entity.LPlaylist
import com.lalilu.lmedia.entity.SongInPlaylist
import com.lalilu.lmedia.extension.DateConverter
import com.lalilu.lmedia.extension.SourceTypeConverter
import com.lalilu.lmedia.extension.UriConverter

@Database(
    version = 8,
    exportSchema = true,
    entities = [
        LPlaylist::class,
        LHistory::class,
        SongInPlaylist::class
    ],
    autoMigrations = [
        AutoMigration(from = 4, to = 5),
        AutoMigration(
            from = 5, to = 6,
            spec = LDatabase.Migration5to6::class
        ),
        AutoMigration(from = 6, to = 7),
        AutoMigration(
            from = 7, to = 8,
            spec = LDatabase.Migration7to8::class
        )
    ]
)
@TypeConverters(
    DateConverter::class,
    UriConverter::class,
    SourceTypeConverter::class
)
abstract class LDatabase : RoomDatabase() {
    abstract fun playlistDao(): PlaylistDao
    abstract fun historyDao(): HistoryDao
    abstract fun songInPlaylistDao(): SongInPlaylistDao

    @DeleteTable(tableName = "m_net_data")
    class Migration5to6 : AutoMigrationSpec

    @DeleteTable(tableName = "extra_song")
    class Migration7to8 : AutoMigrationSpec
}